import Vue from "vue";
import Vuex from "vuex";
import goods from "@/store/modules/goods";

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        num: 100,
        human: [
            { id: 1, name: '北洋', gender: 'man' },
            { id: 2, name: '南洋', gender: 'man' },
            { id: 3, name: '西洋菜', gender: 'woman' },
        ]
    },
    getters: {
        manNums(state) {
            console.log(111);
            return state.human.filter(v => v.gender === 'man').length
        }
    },
    mutations: {
        addNum(state, num) {
            state.num += num
            console.log(state);
        }
    },
    actions: {
        addNumtwo(context) {
            console.log('哈，我被touch了');
            setTimeout(() => {
                context.commit('addNum', 200)
            }, 1000);
        }
    },
    modules: {
        goods
    },
})

export default store;